package com.sd.view;

import java.util.Vector;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alex.books.Chapter;
import com.sd.activity.r.R;


public class ChapterAdpater extends BaseAdapter {

	private Vector<Chapter> mChapters;
	private Context mContext;
	private LayoutInflater mLayoutInflater;
	
	public ChapterAdpater(Context context, Vector<Chapter> chapters){
		mChapters = chapters;
		mContext = context;
		mLayoutInflater = LayoutInflater.from(context);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mChapters.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mChapters.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		
		if(convertView==null){
			holder = new ViewHolder();
			convertView = mLayoutInflater.inflate(R.layout.chapters_view, null);
			holder.bookName = (TextView)convertView.findViewById(R.id.bookname);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder)convertView.getTag();
		}
		
		Chapter chapter = mChapters.get(position);
		if(chapter.mChapterName == null || chapter.mChapterName.trim().equals("")){
			chapter.mChapterName = "无";
		}
		holder.bookName.setText(chapter.mChapterName);
		return convertView;
	}
	
	class ViewHolder {
		/**
		 * 做法名字
		 */
		RelativeLayout book1;
		/**
		 * 做法介绍
		 */
		TextView bookName;
		/**
		 * 做法加价
		 */
		RelativeLayout book3;
	}
	

}
